﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Threading.Tasks;
using System.Windows;
using WPFExcelReport;
using INTEX.DataBase.Tools;
using INTEX.DataBase;
using WPFExcelReport.Controls;
using System.Windows.Controls;
namespace INTEX.SCHEDULER
{
    public partial class ITXSSPA : ViewModelBase
    {

        SETINTEXDB INTEXDB = new SETINTEXDB();
        public string ApplicationPath
        {
            get { return System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath); }
        }
        private double _GDays;
        public double GDays
        {
            get
            {
                return _GDays;
            }
            set
            {
                _GDays = value;
                MCALENDAR.GDays = value;
                DrawCalendar();
                UpdateCalendar();
            }
        }
        private double _HistoryDays;
        public double HistoryDays
        {
            get
            {
                return _HistoryDays;
            }
            set
            {
                _HistoryDays = value;
                MCALENDAR.HistoryDays = value;
                DrawCalendar();
                UpdateCalendar();
            }
        }
        
        private double _GDensity;
        public double GDensity
        {
            get
            {
                return _GDensity;
            }
            set
            {
                if (GDensity == value)
                    return;
                _GDensity = value;
                MCALENDAR.GDensity = value;
                DrawCalendar();
                ReSetDensity();
            }
        } 
        public Dictionary<string, UIAM> MachinesLib
        {
            get;
            set;
        }
        public Dictionary<string, object> JobsLib
        {
            get;
            set;
        }
        public NameScope Pagescope
        {
            get;
            set;
        }

        public DateTime NOW;
        public MCALENDAR _MCALENDAR=null;
        public MCALENDAR MCALENDAR
        {
            get
            {
                if(_MCALENDAR==null)
                { 
                    _MCALENDAR = new MCALENDAR();
                    NOW = DateTime.Now;
                    _MCALENDAR.MachineID = "calendar";
                    _MCALENDAR.NOW = NOW;
                }
                return _MCALENDAR;
            }
        }
        public string MODE = "S";
        public DateTime CalendarStart
        {
            get
            {
                return MCALENDAR.CalendarStart;
            }
        }
        public StackPanel MachinePanel;
        public StackPanel GanttPanel;
        public StackPanel ZoneCalendar;
        public DataTable srcSRULES
        {
            get
            {
                if (SetEnv.Tables.Contains("ICC_SRULES"))
                {
                    return SetEnv.Tables["ICC_SRULES"];
                }
                else
                    return null;
            }
        }
        public DataTable srcJJRULES
        {
            get
            {
                if (SetEnv.Tables.Contains("ICC_JJRULES"))
                {
                    return SetEnv.Tables["ICC_JJRULES"];
                }
                else
                    return null;
            }
        } 
        public DataTable TBAM
        {
            get
            {
                if (SetEnv.Tables.Contains("AMSTAMM"))
                {
                    return SetEnv.Tables["AMSTAMM"];
                }
                else
                    return null;
            }
        }

        public DataTable TBSPSPIN
        {
            get
            {
                if (SetEnv.Tables.Contains("ICC_SPINSPEED"))
                {
                    return SetEnv.Tables["ICC_SPINSPEED"];
                }
                else
                    return null;
            }
        }
        public DataTable TBSTDM
        {
            get
            {
                if (SetEnv.Tables.Contains("ICC_STDMACHINE"))
                {
                    return SetEnv.Tables["ICC_STDMACHINE"];
                }
                else
                    return null;
            }
        }
        public DataTable TBJOBSHOW
        {
            get
            {
                if (SetEnv.Tables.Contains("ICC_PLANSETUP"))
                {
                    return SetEnv.Tables["ICC_PLANSETUP"];
                }
                else
                    return null;
            }
        }

        public DataTable TVKPJOBS//待排产任务，与ICC_PVKPOS有交集
        {
            get
            {
                if (SetData.Tables.Contains("ICC_MKRF"))
                {
                    return SetData.Tables["ICC_MKRF"];
                }
                else
                    return null;
            }
        }
        public DataTable TBMAT//原料清单
        {
            get
            {
                if (SetData.Tables.Contains("MATTB"))
                {
                    return SetData.Tables["MATTB"];
                }
                else
                    return null;
            }
        }
        public DataTable SIMULATIONUSEDJOBS//已经确认的排产
        {
            get
            {
                if (!SetProd.Tables.Contains("CMKRF"))
                {
                    DataTable tb = TVKPJOBS.Clone();
                    tb.TableName = "CMKRF";
                    SetProd.Merge(tb);
                }
                return SetProd.Tables["CMKRF"];
            }
        }
        public DataTable BASICJOBS//基础的独立任务纯粹的ICC_MKRF表
        {
            get
            {
                if (SetProd.Tables.Contains("ICC_MKRF"))
                {
                    return SetProd.Tables["ICC_MKRF"];
                }
                else
                    return null;
            }
        }
        public DateTime HLATIME = DateTime.Now;
        public double HLAMinutes = 0;
        public ITXSSPA()
        {
            SetEnv = new DataSet();
            SetProd = new DataSet();
            SetData = new DataSet();
            JobsLib = new Dictionary<string, object>();
            MachinesLib = new Dictionary<string, UIAM>();
            MODE = "S";
        }
    }
}

